home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_high.lha / LEDA-3.1c-high / man / segment.tex < prev    next >
Encoding:
Text File  |  1994-08-05  |  4.2 KB  |  120 lines

  1. \bigskip
  2. \bigskip
  3. {\magonebf 6.1.2 Segments (segment)}
  4.  
  5. {\bf 1. Definition}
  6.  
  7. An instance $s$ of the data type $segment$ is a directed straight line 
  8. segment in the two-dimensional plane, i.e., a straight line segment $[p,q]$ 
  9. connecting two points $p,q \in \real^2$. $p$ is called the start point
  10. and $q$ is called the end point of $s$. The length of $s$ is the euclidean 
  11. distance between $p$ and $q$. The angle between a right oriented horizontal 
  12. ray and $s$ is called the direction of $s$. The segment $[(0,0),(0,0)]$ 
  13. is said to be empty.
  14.  
  15. \def\name{$segment$}
  16. \def\type{$segment$}
  17.  
  18. {\bf 2. Creation}
  19.  
  20. a) \create s (point\ p,\ point\ q)
  21.  
  22. b) \create s (double\ x_1,\ double\ y_1,\ double\ x_2,\ double\ y_2)
  23.  
  24. c) \create s (point\ p,\ double\ \alpha,\ double\ d)
  25.  
  26. d) \create s {}
  27.  
  28.  
  29. introduces a variable \var\ of type \name. \var\ is initialized to the segment 
  30. from $p$ to $q$ (variant a), to the segment from $(x_1,y_1)$ to $(x_2,y_2)$
  31. (variant v), to the segment with start point $p$, direction $\alpha$, and 
  32. length $d$ (variant c), or to the empty segment (variant d).
  33.  
  34.  
  35. \bigskip
  36. {\bf 3. Operations}
  37.  
  38. \medskip
  39. \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
  40. \+\op point   start {}
  41.                            {returns the start point of segment \var.}
  42. \smallskip
  43. \+\op point   end {}
  44.                            {returns the end point of segment \var.}
  45. \smallskip
  46. \+\op double    xcoord1 {}
  47.                            {returns the x-coordinate of \var.start().}
  48. \smallskip
  49. \+\op double    ycoord1 {}
  50.                            {returns the y-coordinate of \var.start().}
  51. \smallskip
  52. \+\op double    xcoord2 {}
  53.                            {returns the x-coordinate of \var.end().}
  54. \smallskip
  55. \+\op double    ycoord2 {}
  56.                            {returns the y-coordinate of \var.end().}
  57. \smallskip
  58. \+\op double    length {}
  59.                            {returns the length of \var.}
  60. \smallskip
  61. \+\op double   direction {} 
  62.                         {returns the direction of \var\ as an angle in}
  63. \+\nop                  {the intervall $(-\pi,\pi]$.}
  64. \smallskip
  65. \+\op double   angle {segment\ t} 
  66.                         {returns the angle between \var\ and $t$, i.e.,}
  67. \+\nop                  {$t$.direction() - \var.direction().}
  68. \smallskip
  69. \+\op double   angle {} 
  70.                         {returns \var.direction().}
  71. \smallskip
  72. \+\op bool   horizontal {} 
  73.                         {returns true iff \var\ is horizontal.}
  74. \smallskip
  75. \+\op bool   vertical {} 
  76.                         {returns true iff \var\ is vertical.}
  77. \smallskip
  78. \+\op double   slope {}
  79.                         {returns the slope of $s$.}
  80. \+\nop                  { \precond  \var\  is not vertical.}
  81. \smallskip
  82. \+\op bool    intersection {segment\ t,\ point\&\ p} {}
  83. \+\nop                     {if $s$ and $t$ are not collinear and intersect the}
  84. \+\nop                     {intersection point is assigned to $p$ and true is}
  85. \+\nop                     {returned, otherwise false is returned.}
  86. \smallskip
  87. \+\op segment rotate {point\ q,\ double\ \alpha}
  88.                         {returns the segment created by a rotation of $s$}
  89. \+\nop                  {about point $q$ by angle $\alpha$.}
  90. \smallskip
  91. \+\op segment rotate {double\ \alpha}
  92.                         {returns $s$.rotate($s$.start(),$\alpha$).}
  93. \smallskip
  94. \+\op segment translate {vector\ v} {}
  95. \+\nop                     {returns $s+v$, i.e., the segment created by}
  96. \+\nop                     {translating $s$ by vector $v$. \precond $v$}
  97. \+\nop                     {has dimension 2.}
  98. \smallskip
  99. \+\op segment translate {double\ alpha,\ double\ d} {}
  100. \+\nop                  {returns the segment created by a translation of }
  101. \+\nop                  {$s$ in direction $\alpha$ by distance $d$.}
  102. \smallskip
  103.  
  104. \bigskip
  105. {\bf 3. Operators }
  106. \medskip
  107. \+&$bool$       &$segment$ ==    $segment$  &test for equality\cr
  108. \smallskip
  109. \+&$bool$       &$segment$\ !=   $segment$  &test for inequality\cr
  110. \smallskip
  111. \+&$segment$    &$segment$ +\ \  $vector$  &translation by vector\cr
  112. \medskip
  113. Input and output operators:
  114. \medskip
  115. \+&$ostream\&$ &$ostream << segment$ &writes a segment to an output stream.\cr
  116. \smallskip
  117. \+&$istream\&$ &$istream >> segment$ &reads the coordinates of a segment (four doubles)\cr
  118. \+&            &                     &from an input stream.\cr
  119.  
  120.